<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Customer</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>游戏枚举常量配置(公司平台)</legend>
            <div style="margin:10px;">
                <button type="button" class="layui-btn" id="upload-item" title="D_道具信息表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 道具配置
                </button>
                <button type="button" class="layui-btn" id="upload-equipconfig" title="Z_装备配置表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 装备配置
                </button>
                <button type="button" class="layui-btn" id="petconfig" title="H_魂侍配置表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> H_魂侍配置表
                </button>
                <button type="button" class="layui-btn" id="upload-map" title="D-地图传送配置表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 地图配置
                </button>
                <button type="button" class="layui-btn" id="upload-operType" title="操作类型需求.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 操作类型
                </button>
                <button type="button" class="layui-btn" id="upload-equip-attr" title="S-属性枚举表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 属性枚举
                </button>

                <button type="button" class="layui-btn" id="upload-task" title="R_任务配置表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 任务配置表
                </button>
                <button type="button" class="layui-btn" id="upload-gem" title="宝石枚举.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 宝石枚举
                </button>
          <!--      <button type="button" class="layui-btn" id="upload-game-goods" title="N-内购表(官方).xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 游戏内购商品 -->
                </button>
                <button type="button" class="layui-btn" id="equipLimit" title="D-道具日志记录监控清单.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 道具日志监控清单1
                </button>
                <button type="button" class="layui-btn" id="soulTalent" title="h-魂魄天赋表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 魂魄天赋表
                </button>
                <button type="button" class="layui-btn" id="souSkill" title="h-魂魄技能表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 魂魄技能表
                </button>
                <button type="button" class="layui-btn" id="petAttr" title="C-宠物属性表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 宠物属性表
                </button>
                <button type="button" class="layui-btn" id="petSkill" title="C-宠物技能表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 宠物技能表
                </button>
                <button type="button" class="layui-btn" id="cashMonitor" title="返利套现监控表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> 返利套现监控表
                </button>
                <button type="button" class="layui-btn" id="activelist" title="H-活动排期表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> H-活动排期表
                </button>
                <button type="button" class="layui-btn" id="activeatrrlist" title="H-活动规则表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i> H-活动规则表
                </button>
                <button type="button" class="layui-btn" id="gift" title="H-活动规则表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i>  礼包码
                </button>
                <button type="button" class="layui-btn" id="gamemalllist" title="S-商城道具表.xlsx">
                    <i class="layui-icon layui-icon-upload"></i>  商城道具配置表
                </button>

            </div>
            <div style="margin:10px;">
                <button type="button" class="layui-btn" id="any">
                    <i class="layui-icon layui-icon-upload"></i> 导入功能测试
                </button>
            </div>
        </fieldset>



        
        <div class="layuimini-main">
            <fieldset class="table-search-fieldset">
                <legend>服分组</legend>
                <div style="margin: 10px 10px 10px 10px">
                    <form class="layui-form layui-form-pane" action="" lay-filter="table-search">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">分组名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="name" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary"  lay-submit
                                        lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </div>
            </fieldset>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add" auth="admin:add">内购商品配置分组添加</button>
                </div>
            </script>
            <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
            <script type="text/html" id="currentTableBar">
                <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit" auth="serverGroup:edit">编辑</a>
                <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete" auth="serverGroup:delete">删除</a>
            </script>
        </div>
    </div>
</div>
</body>
</html>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>

    layui.use(['upload','form'],function () {
        var upload = layui.upload,$=layui.$;   
         form = layui.form,
         table = layui.table;
         
         
         //表
         table.render({
            elem: '#currentTableId',
            url: '/admin/configGroup/paginate',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'print' ],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 80, title: 'ID'},
                {field: 'name', title: '配置分组名称'},
                {field: 'type', title: '配置标识'},
                {field: 'channel_info', title: '分配包组'},

                {title: '配置上传', width: 120, templet: function(d){
                    return '<button type="button" class="layui-btn layui-btn-xs upload-config" id="upload_'+d.id+'" data-type="'+d.type+'">' +
                           '<i class="layui-icon layui-icon-upload"></i> 上传内购商品配置</button>';
                }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });
        
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var searchData = data.field;
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where:searchData
            }, 'data');
            return false;
        });

        
           /**
         * toolbar监听事件
         */
         table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%', '80%'],
                    content: 'form.html',
                });

            }
        });

       
         
         
        var excelMime = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
       // var dataSelect = document.getElementById('data-select');
       // var selectedType = dataSelect.value;
            // 获取选择框的值
          //  selectedType = this.value;
          //  console.log('切换选中值',selectedType)

            ///QQ渠道

            
            table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['80%', '80%'],
                    content: 'form.html?id='+obj.data.id,
                });

                return false;
            } else if (obj.event === 'delete') {
                var delPop = layer.confirm('确定要删除吗?',{icon:3,title:"提示"},function(){
                    $.post('/admin/configGroup/'+obj.data.id,{_method:'delete'},function (res) {
                        if (res.code === 0){
                            layer.msg('删除成功',{icon:1,time:500},function(){
                                table.reload('currentTableId');
                            })
                            table.reload()
                            layer.close(delPop)
                        } else {
                            layer.msg(res.msg,{icon:2})
                        }
                    });
                })

            }
            
            else if (obj.event === 'addgoods') {
                console.log('点击上传按钮');
                console.log('type值:', obj.data.type);
                
                var uploadBtn = $('<button type="button" id="tempUpload" style="display:none;">上传</button>');
                $('body').append(uploadBtn);
                console.log('创建临时按钮');
                
                var uploadInst = upload.render({
                    elem: '#tempUpload',
                    trigger: 'click',
                    auto: true,
                    multiple: false,
                    data: {
                        table: 'game_goods_qqs',
                        name: "N-内购表(QQ大厅).xlsx",
                        type: obj.data.id
                    },
                    choose: function(obj) {
                        console.log('选择文件');
                    },
                    before: function(obj) {
                        console.log('开始上传');
                        layer.load();
                    },
                    done: function(res) {
                        console.log('上传完成', res);
                        layer.closeAll('loading');
                        if (res.code !== 0) {
                            layer.msg(res.msg, {icon: 2});
                        } else {
                            layer.msg('导入成功', {icon: 1});
                            table.reload('currentTableId');
                        }
                        uploadBtn.remove();
                    },
                    error: function(index, upload) {
                        console.log('上传错误', index, upload);
                        layer.closeAll('loading');
                        layer.msg('上传失败，请重试', {icon: 2});
                        uploadBtn.remove();
                    }
                });
                
                console.log('触发上传');
                uploadBtn.click();
            }
            
        });
            
            upload.render({
                elem: '#upload-game-goods-qq',
                data:{table:'game_goods_qq',name:"N-内购表(QQ大厅).xlsx"},
                exts:"xlsx",
                acceptMime:excelMime,
                url:"/admin/excel/import",
                done:function(res){
                    if (res.code !==0 ){
                        layer.msg(res.msg,{icon:2})
                    } else {
                        layer.msg('导入成功',{icon:1})
                    }
                }
            });

        ///变态渠道

        upload.render({
            elem: '#upload-game-goods-bt',
            data:{table:'game_goods_bt',name:"N-内购表(青衣).xlsx"},
            exts:"xlsx",
            acceptMime:excelMime,
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

            ///

            upload.render({
                elem: '#upload-game-goods',
                data:{table:'game_goods',name:"N-内购表(官方).xlsx"},
                exts:"xlsx",
                acceptMime:excelMime,
                url:"/admin/excel/import",
                done:function(res){
                    if (res.code !==0 ){
                        layer.msg(res.msg,{icon:2})
                    } else {
                        layer.msg('导入成功',{icon:1})
                    }
                }
            });

        upload.render({
            elem: '#any',
            data:{table:'any',name:'any'},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    console.log( JSON.stringify(res.data) )
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

        upload.render({
            elem: '#upload-item',
            data:{table:'equip',name:"D_道具信息表.xlsx"},
            auto:true,
            accept:'file',
            exts:"xlsx",
            acceptMime:excelMime,
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

        upload.render({
            elem: '#upload-equipconfig',
            data:{table:'equipconfig',name:"Z_装备配置表.xlsx"},
            auto:true,
            accept:'file',
            exts:"xlsx",
            acceptMime:excelMime,
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });


        upload.render({
            elem: '#petconfig',
            data:{table:'petconfig',name:"H_魂侍配置表.xlsx"},
            auto:true,
            accept:'file',
            exts:"xlsx",
            acceptMime:excelMime,
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });
        upload.render({
            elem: '#upload-map',
            data:{table:'map',name:"D-地图传送配置表.xlsx"},
            //auto:false,
            exts:"xlsx",
            acceptMime:excelMime,
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });
        upload.render({
            elem: '#upload-operType',
            data:{table:'oper_type',name:"C-操作码.xlsx"},
            //auto:false,
            exts:"xlsx",
            acceptMime:excelMime,
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });
        upload.render({
            elem: '#upload-equip-attr',
            data:{table:'equip_attr',name:"S-属性枚举表.xlsx"},
            exts:"xlsx",
            acceptMime:excelMime,
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });
        upload.render({
            elem: '#upload-gem',
            data:{table:'gem_list',name:"宝石枚举.xlsx"},
            exts:"xlsx",
            acceptMime:excelMime,
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });
        upload.render({
            elem: '#upload-task',
            data:{table:'task',name:"R_任务配置表.xlsx"},
            exts:"xlsx",
            acceptMime:excelMime,
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

        upload.render({
            elem: '#equipLimit',
            data:{table:'equip_monitor_limit',name:$('#equipLimit').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

        upload.render({ //魂魄天赋
            elem: '#cashMonitor', // soulTalent souSkill petAttr cashMonitor
            data:{table:'cashMonitor',name:$('#cashMonitor').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });


        upload.render({ //活动排期表
            elem: '#activelist',
            data:{table:'activelist',name:$('#activelist').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });
        upload.render({ //礼包码
            elem: '#gift',
            data:{table:'gift',name:$('#gift').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

        upload.render({ //商城道具配置表
            elem: '#gamemalllist',
            data:{table:'gamemalllist',name:$('#gamemalllist').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

        upload.render({ //活动排期表
            elem: '#activeatrrlist',
            data:{table:'activeatrrlist',name:$('#activeatrrlist').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });
        upload.render({ //魂魄天赋
            elem: '#soulTalent', // soulTalent souSkill petAttr petSkill
            data:{table:'soul_talent',name:$('#soulTalent').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });
        upload.render({ //魂魄技能
            elem: '#souSkill',
            data:{table:'soul_skill',name:$('#souSkill').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

        upload.render({ //魂魄技能
            elem: '#petAttr',
            data:{table:'pet_attr',name:$('#petAttr').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

        upload.render({ //宠物技能
            elem: '#petSkill',
            data:{table:'pet_skill',name:$('#petSkill').attr('title')},
            exts:"xlsx",
            acceptMime:excelMime,
            trigger: 'click', //绑定点击事件
            url:"/admin/excel/import",
            done:function(res){
                if (res.code !==0 ){
                    layer.msg(res.msg,{icon:2})
                } else {
                    layer.msg('导入成功',{icon:1})
                }
            }
        });

        // 修改通用上传配置处理部分
        $(document).on('click', '.upload-config', function(e){
            e.preventDefault();
            var type = $(this).data('type');
            
            // 创建隐藏的文件输入框
            var fileInput = $('<input type="file" accept=".xlsx" style="display:none">');
            
            // 监听文件选择变化
            fileInput.on('change', function(){
                if(this.files.length > 0){
                    var file = this.files[0];
                    var formData = new FormData();
                    formData.append('file', file);  // 文件数据
                    formData.append('table', 'game_goods_type');  // 表名
                    formData.append('type', type);  // 配置类型
                    formData.append('name', file.name);  // 使用实际的文件名
                    
                    // 显示loading
                    layer.load();
                    
                    // 发送AJAX请求
                    $.ajax({
                        url: '/admin/excel/import',
                        type: 'POST',
                        data: formData,
                        processData: false,
                        contentType: false,
                        success: function(res){
                            layer.closeAll('loading');
                            if(res.code !== 0){
                                layer.msg(res.msg, {icon: 2});
                            } else {
                                layer.msg('导入成功', {icon: 1});
                                table.reload('currentTableId');
                            }
                        },
                        error: function(){
                            layer.closeAll('loading');
                            layer.msg('上传失败，请重试', {icon: 2});
                        },
                        complete: function(){
                            fileInput.remove();
                        }
                    });
                }
            });
            
            $('body').append(fileInput);
            fileInput.click();
        });

    })

</script>